package com.example.game_dafangdaxie.resUtils;

import android.content.Context;
import android.media.SoundPool;

import com.example.game_dafangdaxie.R;

import java.util.HashMap;

public class mSoundPool {
    private Context context;

    private static SoundPool soundPool;
    private static HashMap<Integer,Integer> SoundId=new HashMap<>();
    public mSoundPool(Context context) {
        this.context=context;
       SoundPool.Builder sp=new SoundPool.Builder();
       sp.setMaxStreams(2);
       soundPool=sp.build();
       SoundId.put(0,soundPool.load(context, R.raw.sound_down_piece,0));
       SoundId.put(1,soundPool.load(context,R.raw.sound_reward,0));
    }

    public void start(int i){
        if(i>1){
            i=i%2;
        }
        if(soundPool!=null&&!SoundId.isEmpty()){
            soundPool.play(SoundId.get(i), 1f, 1f, 0, 0, 1);
        }
    }
    public void Close(){
        if(soundPool!=null){
            soundPool.autoPause();
            soundPool.release();
            soundPool=null;
        }
    }
}









